package android.meetingatsb

import android.meetingatsb.common.Requirement
import android.meetingatsb.common.User
import android.meetingatsb.widget.RequirementFragment
import android.meetingatsb.widget.UserInfoFragment
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.ImageView

class MatchSuccessActivity : AppCompatActivity() {
    lateinit var matchRequirement: Requirement
    lateinit var matchUser: User

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        getData()
        setFragment()
        setContentView(R.layout.activity_match_success)
        setListener()
    }

    private fun setListener() {

        findViewById<ImageView>(R.id.match_submit).setOnClickListener {
            intent.setClass(this, DatingActivity::class.java)
            intent.putExtra("matchUser", matchUser)
            startActivity(intent)
        }
        findViewById<ImageView>(R.id.match_cancel).setOnClickListener {

        }
    }

    //设置fragment
    private fun setFragment() {

        val fragTran = fragmentManager.beginTransaction()

        val userInfoFragment = UserInfoFragment()
        fragTran.replace(R.id.user_info_fragment, userInfoFragment)
        val userInfoBundle = Bundle()
        userInfoBundle.putParcelable("user", matchUser)
        userInfoFragment.arguments = userInfoBundle

        val requirementFragment = RequirementFragment()
        fragTran.replace(R.id.user_requirement_fragment, requirementFragment)
        val requirementBundle = Bundle()
        requirementBundle.putParcelable("requirement", matchRequirement)
        requirementFragment.arguments = requirementBundle
        fragTran.commit()
    }

    private fun getData() {
        matchUser = User("大学生", "大学生", "华南理工大学", 21, "女", 5.0F)
        matchRequirement = Requirement("大学学生",
                "番禺区中环东路华南理工大学",
                "2017/07/19 17:00 - 21:00",
                "暂无")
    }
}